using AutoMapper;
using net_work.Common;
using net_work.Common.Request;
using net_work.Common.Result;
using net_work.Data.DTO.Cam;
using net_work.Data.Entity.Cam;
using net_work.IRepository.Cam;
using net_work.IRepository.Hmw;
using net_work.IService.Cam;

namespace net_work.Service.Cam;

public class ApplyService(
    IUserContext userContext,
    IMapper mapper,
    IApplyRepository applyRepository,
    IBankQuestionRepository bankQuestionRepository)
    : IApplyService
{
    public Task<PagedResult<Apply>> GetApplysPagedAsync(PagedRequest request)
    {
        return applyRepository.GetPagedAsync(request);
    }

    public Task<Apply?> SelectByIdAsync(long applyId)
    {
        return applyRepository.GetByIdAsync(applyId);
    }

    public async Task<long> InsertApply(ApplyAddRequest applyAddRequest)
    {
        var applyAddRequestBackend = mapper.Map<ApplyAddRequestBackend>(applyAddRequest);
        applyAddRequestBackend.UserId = userContext.UserId;

        return await applyRepository.InsertAsync(applyAddRequestBackend);
    }

    public async Task<int> UpdateApply(ApplyUpdateRequest applyUpdateRequest)
    {
        if (applyUpdateRequest.Id <= 0)
        {
            return -1;
        }

        return await applyRepository.UpdateAsync(applyUpdateRequest) ? 1 : -1;
    }

    public async Task<int> DeleteApplyByIds(List<long> ids)
    {
        return await applyRepository.DeleteByIdsAsync(ids) ? 1 : -1;
    }
}